<?php
namespace wogu2\mvc\router\http;

use wogu2\mvc\router\RouterInterface;
use wogu2\stdlib\RequestInterface;

class Query implements RouterInterface
{
    public function match(RequestInterface $request) {
        $namespace = $request->getParameter('n', array('get', 'post'));
        $action = $request->getParameter('a', array('get', 'post'));
        
        if(empty($namespace)) {
            
        }
        
        $routerConfig = $this->_runtime->routerConfig;
        if($namespace) {
            
            if(!$action) {
                $action = $routerConfig['defaultAction'];
            }
            
            if(!isset($this->_runtime->actionsMap[$namespace][$action])) {
                $namespace = $routerConfig['defaultErrorNamespace'];
                $action = $routerConfig['defaultErrorAction'];
            }
            
            $this->_runtime->actionConfig = $this->_runtime->actionsMap[$namespace][$action];
            return true;
        }
        
        return false;
    }
    
    private function _defaultAction($request) {
        $routerConfig = $this->_runtime->routerConfig;
        $namespace = $routerConfig['defaultNamespace'];
        $action = $routerConfig['defaultAction'];
        $this->_runtime->actionConfig = $this->_runtime->actionsMap[$namespace][$action];
    }
}